package com.yhd.flyweight;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/**
 * @author yhd
 * @email yinhuidong1@xiaomi.com
 * @description TODO
 * @since 2021/5/21 下午6:33
 */
public class YuHuaYuan extends XiYu{

    private static Map<String,JiShi> xuantai = new HashMap<>();
    static {
        xuantai.put("萌萌",new JiShi(8375,"萌萌",false));
        xuantai.put("程程",new JiShi(13,"程程",false));
    }

    @Override
    void tuiyou(String name) {
        Collection<JiShi> values = xuantai.values();
        if (name==null || "".equals(name)){
            for (JiShi v : values) {
                if (!v.isZhong()){
                    System.out.println(v.getId()+"号技师，"+v.getName()+"正在为你服务！！！");
                    v.setZhong(true);
                    return ;
                }
            }
            throw  new RuntimeException("服务员正在上钟");
        }else {
            JiShi v = xuantai.get(name);
            if (!v.isZhong()){
                System.out.println(v.getId()+"号技师，"+v.getName()+"正在为你服务！！！");
                v.setZhong(true);
            }else{
                throw  new RuntimeException("服务员正在上钟");
            }

        }
    }

    @Override
    void done(String name){
        System.out.println(xuantai.get(name).setZhong(false) + "服务完毕，下钟！");
    }
}
